home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of NeuroSolutions Step component
-
- #include "NSDLL.h"
-
- /*****************************/
- /* Gradient search procedure */
-
- __declspec(dllexport) void performStep(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *weights, // Pointer to the vector of weights
- int length, // Length of the weight vector
- NSFloat *gradient, // Pointer to the vector of gradients, one for each weight
- NSFloat *step, // Pointer to the learning rate/s
- BOOL individual, // Indicates whether there is one learning rate for all weights (FALSE),
- // or each weight has its own learning rate (TRUE)
- int stepDivisor,// The number each step size should be divided by
- BOOL decayWeights, // TRUE if weight decay is active
- NSFloat decayRate // Rate to decay weights if weight decay is active
- )
- {
- register int i;
-
- for (i=0; i<length; i++)
- weights[i] += (step[individual?i:0]/stepDivisor) * gradient[i] - (decayWeights ? weights[i] * decayRate : 0.0f);
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
- /*
- __declspec(dllexport) DLLData *allocStep(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int length, // Length of the weight vector
- BOOL individual // Indicates whether their is one learning rate for all weights (FALSE),
- // or each weight has its own learning rate
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- return instance;
- }
-
- __declspec(dllexport) void freeStep(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
- */